'''
Created on 26/03/2011

@author: andrew
'''

from sqlalchemy import create_engine, Table, Column, MetaData
from sqlalchemy import Boolean, Integer, Unicode, String
from sqlalchemy.engine.url import URL
from sqlalchemy.orm import sessionmaker, mapper
from sqlalchemy.ext.declarative import declarative_base

import FindFiles
import Database

class Music(Database.Base):
    '''
    classdocs
    '''

    __tablename__ = 'tb_music'
    
    id = Column(Integer, primary_key=True)
    artist = Column(String(255), nullable=True)
    album = Column(String(255), nullable=True)
    title = Column(String(255), nullable=True)
    listenerCount = Column(Integer, nullable=True)
    path = Column(String(4000), nullable=False)

    def __init__(self,musicFile=None):
        '''
        Constructor
        '''
        self.musicFile = musicFile
        
        if musicFile != None:
            self.artist = musicFile.artist
            self.title = musicFile.title
            self.album = musicFile.album
            self.path = musicFile.path

    @property
    def musicFile(self):
        return FindFiles.getMusic(self.path)
    
    @musicFile.setter
    def musicFile(self,musicFile):
        pass

    def delete(self):
        self.MusicFile.delete()
        
    def __repr__(self):
        return "<Music(id:'%s', title:'%s', album:'%s', artist:'%s', path:'%s')>" % (self.id, self.title, self.album, self.artist, self.path)


Database.Base.metadata.create_all()





